using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class dog : MonoBehaviour
{

    private Rigidbody2D rb;
    public Transform leftpoint, rightpoint;
    public float Speed;
    private bool Faceleft = true;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        transform.DetachChildren();
    }

    void Update()
    {
        Movement();
    }

    void Movement()
    {
        if (Faceleft)
        {
            rb.velocity = new Vector2(-Speed, rb.velocity.y);
            if (transform.position.x < leftpoint.position.x)
            {
                // transform.localScale=new Vector3(-7,7,7);
                Faceleft = false;
            }
        }
        else
        {
            rb.velocity = new Vector2(Speed, rb.velocity.y);
            if (transform.position.x > rightpoint.position.x)
            {
                // transform.localScale=new Vector3( 7,7,7);
                Faceleft = true;
            }
        }
    }
}
